package com.dhcc.sdc.cdss.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.cdss.entity.SdcCdssItemResultEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssItemResultService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 
 * 
 * @ClassName: SdcCdssItemResultController
 * @Description: TODO
 * @author sunyingjie
 * @date 2022-07-22 10:31:26
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdccdssitemresult")
public class SdcCdssItemResultController extends BaseController {

	private String PREFIX = "/backend/sdc/sdccdssitemresult/";

	@Autowired
	private ISdcCdssItemResultService sdcCdssItemResultService;
	

    /**
     * 跳转到列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdccdssitemresult.html";
    }
	
    /**
     * 跳转到新增
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdccdssitemresult_add.html";
    }
	
	/**
     * 跳转到修改
     */
    @RequestMapping("/to_update/{sdcCdssItemResultId}")
    public String toUpdate(@PathVariable Long sdcCdssItemResultId, Model model) {
        SdcCdssItemResultEntity sdcCdssItemResult = this.sdcCdssItemResultService.selectById(sdcCdssItemResultId);
        model.addAttribute("sdcCdssItemResult",sdcCdssItemResult);
        return PREFIX + "sdccdssitemresult_edit.html";
    }

    /**
     * 获取列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcCdssItemResultEntity> page = new PageFactory<SdcCdssItemResultEntity>().defaultPage();
        List<SdcCdssItemResultEntity> result = this.sdcCdssItemResultService.page(page,params);
        page.setRecords((List<SdcCdssItemResultEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssItemResultEntity sdcCdssItemResult) {
        if (CommonUtil.isOneEmpty(sdcCdssItemResult)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        sdcCdssItemResult.insert();
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Long sdcCdssItemResultId) {
	
        this.sdcCdssItemResultService.deleteById(sdcCdssItemResultId);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssItemResultEntity sdcCdssItemResult) {
        if (CommonUtil.isOneEmpty(sdcCdssItemResult)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        SdcCdssItemResultEntity old = this.sdcCdssItemResultService.selectById(sdcCdssItemResult.getId());

        old.setEpisodeId(sdcCdssItemResult.getEpisodeId());
        old.setNodeId(sdcCdssItemResult.getNodeId());
        old.setResult(sdcCdssItemResult.getResult());
        old.updateAllColumnById();
        return R.ok();
    }
	
}
